// pages/user/user.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {
      nickName: '',
      avatar: '../../images/icons8-mango.png',
      userId: ''
    },
    date: '2000-09-01',
    dateStatus: false,
    sexStatus: false,
    regionStatus: false,
    array: ['男', '女', '未知'],
    index: 0,
    region: ['广东省', '广州市', '海珠区'],
    customItem: '全部'
  },

  onChooseAvatar(e) {
    const { avatarUrl } = e.detail
    App.globalData.userInfo.avatarUrl = avatarUrl
    this.setData({
      userInfo: {
        avatar: avatarUrl,
        nickName: this.data.userInfo.nickName,
        userId: this.data.userInfo.userId,
      }
    })
  },


  bindDateChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value,
      dateStatus: true
    })
  },


  phoneNumberMethod(e) {
    const data = e.detail.value;
    if (data.length == 0) {
      wx.showToast({
        title: '请输入手机号',
        icon: 'none'
      })
    }
    if (data.length != 11 || !/^1[3456789]\d{9}$/.test(data)) {
      wx.showToast({
        title: '请输入正确的手机号',
        icon: 'none'
      })
    }
    this.setData({
      phoneNumber: data
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.setData({
      userInfo: {
        nickName: app.globalData.userInfo.nickName,
        avatar: app.globalData.userInfo.avatarUrl,
        userId: app.globalData.userInfo.userId
      }
    })
  },

  bindRegionChange: function (e) {
    this.setData({
      region: e.detail.value,
      regionStatus: true
    })
  },

  bindSexChange(e) {
    this.setData({
      index: e.detail.value,
      sexStatus: true
    })
  },

  bindDateChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value,
      dateStatus: true
    })
  },

  onChooseAvatar(e) {
    const { avatarUrl } = e.detail
    app.globalData.userInfo.avatarUrl = avatarUrl
    this.setData({
      userInfo: {
        avatar: avatarUrl,
        nickName: this.data.userInfo.nickName,
        userId: this.data.userInfo.userId
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})